<template>
	<view>
		<back :showBackText="false" customClass="bg-gradual-blue text-white" title="我的错题"></back>
		<view class="flex flex-direction" style="min-height: 100vh;">
			<view class="flex-sub" style="margin-bottom: 270rpx;">
				<view @tap="courseTap" class="course-layout margin-bottom-xs" :data-item="course"
					v-for="(course, idx) in listData" :key="idx">
					<view class="name-layout">
						<text>{{ course.name }}</text>
						<courselabel :code="course.code" :topicCount="'共'+course.count + '题'"></courselabel>					</view>
					<text class="cuIcon-right"></text>
				</view>
				<empty v-if="(isLoad  &&  listData.length <= 0)"></empty>
			</view>
			<adfootbanner></adfootbanner>
		</view>
	</view>
</template>
<script>
	let app = getApp();
	let that = null;
	export default {
		data() {
			return {
				isLoad: false,
				listData: [],
				course_id: 0,
				course: {
					name: '',
					code: '',
					count: ''
				}
			};
		},
		onLoad(options) {
			that = this;
			const {
				course_id = 0
			} = options || {};
			that.course_id = course_id;
		},
		onShow() {
			that.getError();
		},
		methods: {
			getError(e) {
				app.globalData.server
					.postRequest('user/error_question', {
						course_id: that.course_id
					})
					.then(function(t) {
						that.isLoad = true;
						that.listData = t.data;
					})
					.catch(function(a) {
						app.showToast('获取错题列表失败');
					});
			},

			courseTap: function(options) {
				let item = options.currentTarget.dataset.item;
				let url = '../topic/topic?mainType=3' + '&title=【错题】' + item.name + '&id=' + item.course_id;
				uni.navigateTo({
					url: url
				});
			}
		}
	};
</script>
<style src="./error.css"></style>